﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Webdisk;
using System.Data.SqlClient;

namespace Webdisk_New
{
	public partial class Information : Form
	{
		public Information()
		{
			InitializeComponent();
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);

        }

        //设置窗口阴影
        private const int CS_DropSHADOW = 0x20000;
        private const int GCL_STYLE = (-26);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);


        

		

		private void Information_Load(object sender, EventArgs e)
		{
			textBox_name.Text = Temp.TmeploginName;
			System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();//重绘pictureBox，变成圆形
            path.AddEllipse(this.pictureBox_Head.ClientRectangle);
			Region reg = new Region(path);
			this.pictureBox_Head.Region = reg;

            //显示用户信息
            SqlDataReader reader = null;
            reader = DBHelper.GetDataReader(string.Format("select Nickname,Gender,Brithday,Occupation,Hometown,Location,School,Phone,[Blood type],Phone from userInfo where loginName='{0}'", Temp.TmeploginName));
            while (reader.Read())
            {
                textBox_name.Text = reader["Nickname"].ToString();
                comboBox_Gender.Text = reader["Gender"].ToString();
                textBox_date.Text = reader["Brithday"].ToString();
                comboBox_Opt.Text = reader["Occupation"].ToString();
                textBox_Home.Text = reader["Hometown"].ToString();
                textBox_Adderss.Text = reader["Location"].ToString();
                textBox_school.Text = reader["School"].ToString();
                textBox_Phone.Text = reader["Phone"].ToString();
                comboBox_Blood.Text = reader["Blood type"].ToString();
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)//最小化点击
        {
            this.WindowState = FormWindowState.Minimized;//最小化窗体
        }
        //下面两个事件实现了窗口的拖动
        private Point mPoint;//坐标
        private void Information_MouseDown(object sender, MouseEventArgs e)
        {
            mPoint = new Point(e.X, e.Y);
        }

        private void Information_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
            }
        }
        private void pictureBox3_Click(object sender, EventArgs e)//关闭点击
        {
            Close();
        }

        private void Information_FormClosing(object sender, FormClosingEventArgs e)
        {
            Type.AnimateWindow(this.Handle, 300, Type.AW_BLEND | Type.AW_HIDE);//设置窗口淡出
        }

        private void SaveBut_Click(object sender, EventArgs e)
        {
            //点击修改修改用户信息
            DBHelper.Conn.Close();
            DBHelper.ExecuteNonQuery(string.Format("update userInfo set Nickname='{0}',Gender='{1}',Brithday='{2}',Occupation='{3}',Hometown='{4}',Location='{5}',School='{6}',Phone='{7}',[Blood type]='{8}'where loginName='{9}' ",
                textBox_name.Text, comboBox_Gender.Text, textBox_date.Text, comboBox_Opt.Text, textBox_Home.Text, textBox_Adderss.Text, textBox_school.Text, textBox_Phone.Text, comboBox_Blood.Text, Temp.TmeploginName));
            MessageBox.Show("保存成功");
            this.Close();
        }

        private void ExitBut_Click(object sender, EventArgs e)
        {
            this.Close();

        }
    }
}
